package com.wen.controller.biz;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wen.business.service.ContentService;
import com.wen.common.pojo.account.Content;
import com.wen.common.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 文章controller
 */
@RestController
@RequestMapping("/content")
//@CrossOrigin(origins = {"http://localhost:8082", "http://localhost:8848"})
public class ContentController {

    @Autowired
    private ContentService contentService;

    @GetMapping("/page")
    public ResponseResult<?> findPage(@RequestParam(defaultValue = "1") int pageNum,
                                      @RequestParam(defaultValue = "10") int pageSize,
                                      @RequestParam(defaultValue = "") String search) {
        Page<Content> contentPage = contentService.findContentPage(pageNum, pageSize, search);
        return ResponseResult.success(contentPage);
    }

    @PostMapping("/add")
    public ResponseResult<?> add(@RequestBody Content content) {
        contentService.add(content);
        return ResponseResult.success(content);// 新增后又返回了新增数据
    }

    // 更新
    @PutMapping
    public ResponseResult<?> update(@RequestBody Content content) {
        contentService.update(content);
        return ResponseResult.success(content);// 新增后又返回了新增数据
    }
    // 删除
    @DeleteMapping("/{id}")
    public ResponseResult<?> delete(@PathVariable("id") Long id){
        contentService.delete(id);
        return ResponseResult.success();
    }
}
